﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;

namespace BovespaMaintainabilityRules
{
    public sealed class Rule_RegionRules : BaseAddIn.Rules.BaseRuleAddIn
    {
        #region Construtor

        public Rule_RegionRules()
            : base("BovespaRegionRules",
                   "BovespaMaintainabilityRules.BovespaMaintainabilityRules",
                   typeof(Rule_RegionRules).Assembly)
        {
        }

        #endregion

        #region Protected Override Methods

        protected sealed override void Check(CodeClass2 classe)
        {
            LinhaCodigo codigoProblema = null;
            Region regionProblema = null;            
            ListaRegions regionsArquivo = null;
            string arquivo = classe.StartPoint.Parent.Parent.FullName;

            regionsArquivo = new ListaRegions(arquivo);
            regionsArquivo.CarregaRegions(out regionProblema, out codigoProblema);

            if (regionProblema != null)
            {
                GeraProblemaAddIn(arquivo,
                                 regionProblema.LinhaComeco.Value + 1,
                                 regionProblema.ColunaComeco.Value + 1,
                                 "RemoveNotUsedRegionsResolution",
                                 arquivo);
            }

            if (codigoProblema != null)
            {
                GeraProblemaAddIn(arquivo,
                                  codigoProblema.Linha + 1,
                                  codigoProblema.Coluna + 1,
                                  "MemberMustBeInsideRegionResolution",
                                  arquivo);
            }
        }

        #endregion
    }
}
